package com.example.zbh.dsliao.ui.fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zbh.dsliao.R;
import com.example.zbh.dsliao.ui.adapter.MusicListAdapter;

/**
 * Created by zbh on 15/11/18.
 */
public class MusicListFragment extends BaseFragment {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private MusicListAdapter adapter;
    private Context context;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        this.context = context;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_music_list, null);
        //初始化
        tabLayout = (TabLayout) v.findViewById(R.id.tablayout);
        viewPager = (ViewPager) v.findViewById(R.id.viewpagerMusicList);
        return v;
    }

    @Override
    protected void initData() {
        adapter = new MusicListAdapter(getChildFragmentManager());
        viewPager.setAdapter(adapter);
        //tabLayout与viewPager绑定
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.setSelectedTabIndicatorColor(0xff6688ff);
        //可滑动
        tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        //添加图标
        for (int i = 0; i < tabLayout.getTabCount(); i++) {
            tabLayout.getTabAt(2).setIcon(R.mipmap.search_title_icon);
        }


    }
}
